#!/usr/bin/perl -w
# This script was developed to test HTML::TreeBuilder functionality as I
# had never used it before.  Being possibly useful for posterity as a simple
# example, I've decided to include it.

use HTML::TreeBuilder;
$root = HTML::TreeBuilder->new();

$filename = shift;
if(!$filename)
{
	$filename = "test.html";
}
print "*** File: '$filename' ***\n\n";
$root->parse_file($filename);
$root->elementify();

### white space used to indent
my $WHITE = "\t";



sub recurse
{
	my $parent = shift;
	my $white = shift;
	if(!defined($white))
	{
		$white = "";
	}
	
	### this if statement ought to be superfluous except for the initial call
	if(ref($parent) eq 'HTML::Element')
	{
		foreach($parent->content_list())
		{
			if(ref($_) eq 'HTML::Element')
			{
				print $white . $_->tag() . "\n";
				recurse($_, $white . $WHITE);
			}
			else
			{
				print "$white'$_'\n";
			}
		}
	}
	else
	{
		### this piece of code should not be hit if the initial call is made 
		### with an HTML::Element
		print "!$white'$parent'\n";
	}
}

recurse($root);
print "\nend\n";


